package com.prabodha.fruitmap;

import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;

import com.webService.Webservice;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class NewUser extends Activity {
	
	String fname;
	String lname;
	String username;
	String password;
	String address;
	int role;
	double lati=99.7654d;
	double longi=79.7654d;
	SoapObject request;
	SoapSerializationEnvelope envelope;
	
@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_newuser);
	
	 Button submit =(Button) findViewById(R.id.button1);
	 ImageButton map=(ImageButton)findViewById(R.id.imageButton);
	 final EditText firstname=(EditText)findViewById(R.id.fname);
	 final EditText lastname=(EditText)findViewById(R.id.lName);
	 final EditText uname=(EditText)findViewById(R.id.username);
	 final EditText pword=(EditText)findViewById(R.id.password);
	 final EditText addre=(EditText)findViewById(R.id.address);
	 final Spinner rol=(Spinner) findViewById(R.id.spinner1);
	       
	
	
	fname=firstname.getText().toString();
	lname=lastname.getText().toString();
	username=uname.getText().toString();
	password=pword.getText().toString();
	address=addre.getText().toString();
	role=rol.getSelectedItemPosition();
	
	
	Log.d("llllllllllllllllllllllllllname", lname);
	
	map.setOnClickListener(new OnClickListener() {
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent = new Intent(NewUser.this, GoogleMapsActivity.class);
    		startActivity(intent);
			
			
		}
	});
	
	
	
	
	// New user form Submit onClick Listner
	submit.setOnClickListener(new OnClickListener() {
		
		public void onClick(View v) {
			
			fname=firstname.getText().toString();
			lname=lastname.getText().toString();
			username=uname.getText().toString();
			password=pword.getText().toString();
			address=addre.getText().toString();
			role=rol.getSelectedItemPosition();
			Log.d("llllllllllllllllllllllllllname", lname);

			
			
			try{
            	Webservice wb = new Webservice();
           	 
            	wb.METHOD_NAME = "newUser";
            	wb.SOAP_ACTION = "http://fruitMap.com/"+wb.METHOD_NAME;
            	 
            	 request =wb.getRequest();
            	 request.addProperty("fname",fname);
            	 request.addProperty("lname",lname);
            	 request.addProperty("username",username);
            	 request.addProperty("password",password);
            	 request.addProperty("latitude","8778");
            	 request.addProperty("longitude","9987");
            	 request.addProperty("address",address);
            	 request.addProperty("role",role);
            	 
            	 
            	 envelope = wb.setRequestAndGetEnvilop(request); 
            	 SoapPrimitive soap = wb.getPrimitive(envelope);
            	 
            	 if(soap.toString().trim().equals("true")){
            		//showDialog("Successfully login !");
            		
            	
            		 Toast.makeText(NewUser.this, "Successfully added", Toast.LENGTH_LONG).show();
//            		 Intent in = new Intent();
//            		 in.setClass(this,Home.class);
//            		 startActivity(in);
            		// new StoreMapVariable().setVaraible();
            		//Toast.makeText(this,"true",Toast.LENGTH_SHORT).show(); 
            	 }
            	 else{
            		//showDialog("Enter valied User name and password  !");
            		//Toast.makeText(this,"false",Toast.LENGTH_SHORT).show();
            	 }
            
            }catch(Exception ex){
            	ex.printStackTrace();
            	
            }
     
      	  
		}
	});
	 
}
}
